package com.pig.sentinel.context;

import com.pig.sentinel.enums.ProcessTypeEnum;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * 受管理方法中，注解的内容
 *
 * @author lizhiwei
 */
public class MethodSentinelContext {
    private Method exceptionHandler;
    private FlowContext flowContext = new FlowContext();
    private DegradeContext degradeContext = new DegradeContext();

    private Set<ProcessTypeEnum> processTypeEnumSet;

    public MethodSentinelContext(Method exceptionHandler, ProcessTypeEnum[] processTypeEnumSet) {
        this.exceptionHandler = exceptionHandler;
        this.processTypeEnumSet = new HashSet<>(Arrays.asList(processTypeEnumSet));
    }


    public boolean support(ProcessTypeEnum processTypeEnum) {
        return this.processTypeEnumSet.contains(processTypeEnum);
    }
    public Method getExceptionHandler() {
        return exceptionHandler;
    }

    public FlowContext getFlowContext() {
        return flowContext;
    }


    public DegradeContext getDegradeContext() {
        return degradeContext;
    }

}
